﻿using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using my.abp.Application.Contracts.Dtos.Org;
using my.abp.Application.Contracts.IServices.Org;
using my.abp.Application.Contracts.IServices.User;
using my.abp.Domain.IManagers.Org;
using my.abp.Domain.Shared.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Uow;

namespace my.abp.Application.Services.Org
{
	public class SysOrgService : ApplicationService, ISysOrgService
	{
		private ISysOrgManager _sysOrgManagerService;

		public SysOrgService(ISysOrgManager sysOrgManagerService) 
		{
			_sysOrgManagerService = sysOrgManagerService;
		}

		/// <summary>
		/// 获取机构列表
		/// </summary>
		/// <returns></returns>
		[Authorize]
		[DisplayName("获取机构列表")]
		public async Task<List<SysOrg>> GetList([FromQuery] OrgInput input)
		{
			// 获取机构列表
			var userOrgIdList = await _sysOrgManagerService.GetList(input.Id, input.Name, input.Code);
			return userOrgIdList;
		}

		/// <summary>
		/// 增加机构
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[Authorize]
		[DisplayName("增加机构")]
		[HttpPost]
		public async Task<long> AddOrg(AddOrgInput input)
		{
			return await _sysOrgManagerService.AddOrg(input.Adapt<SysOrg>());
		}

		/// <summary>
		/// 增加机构
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[Authorize]
		[DisplayName("更新机构")]
		[HttpPost]
		public async Task UpdateOrg(UpdateOrgInput input)
		{
			await _sysOrgManagerService.UpdateOrg(input.Adapt<SysOrg>());
		}

		/// <summary>
		/// 删除机构
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[Authorize]
		[DisplayName("删除机构")]
		[HttpPost]
		public async Task DeleteOrg(DeleteOrgInput input)
		{
			await _sysOrgManagerService.DeleteOrg(input.Adapt<SysOrg>());
		}
	}
}
